package view;

import java.io.File;
import java.util.HashMap;
import model.*;

public class RepresentationFactory
{
	private static RepresentationFactory instance;
	
	private final HashMap<String,ObjectRepresentation> repSet;
	private final ObjectRepresentation defaultRep;
	
	public static RepresentationFactory getInstance()
	{
		if (instance == null)
			instance = new RepresentationFactory();
		return instance;
	}
	
	private RepresentationFactory()
	{
		repSet = new HashMap<String,ObjectRepresentation>();
		defaultRep = new ObjectRepresentation("default");
	}
	
	public ObjectRepresentation get(GameObject g)
	{
		String gID = g.getTypeId();
		ObjectRepresentation o = repSet.get(gID);
		if (o == null)
		{
			File f = new File("images/"+gID+".png");
			if (f.exists()) 
				repSet.put(gID, new ObjectRepresentation(gID));
			else 
				repSet.put(gID, defaultRep);
			o = repSet.get(gID);
		}
		return o;	
	}
}